package com.neuedu.my12306.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.my12306.entity.UserInfo;
import com.neuedu.my12306.service.IUserInfoService;
import com.neuedu.my12306.util.SpringContextUtil;

/**
 * Servlet implementation class UserInfoServlet
 */
@WebServlet("/ToEditUserInfoServlet.do")
public class ToEditUserInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private IUserInfoService userInfoService;
    public ToEditUserInfoServlet() {
        super();
        //使用IUserInfoService接口解耦合 CheckUserNameServlet  与IUserInfoServiceImpl 的耦合关系
        // userInfoService = new IUserInfoServiceImpl();
         userInfoService = SpringContextUtil.getBean("userService", IUserInfoService.class);
       
    }
	

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//Cookie[] cookies = req.getCookies();
		String uname = req.getParameter("uname");
		if (uname!=null) {
			UserInfo userInfo = userInfoService.findUserInfoByid(uname);
			req.setAttribute("userInfo", userInfo);
			req.getRequestDispatcher("/User/UserManageInfo_Edit.jsp").forward(req, resp);
			//System.out.println(userName);
		}else {
			resp.sendRedirect(req.getContextPath()+"/User/UserManageInfo_Edit.jsp");
			//System.out.println(userName);
		}
		
		
	}



}
